<template>
  <div class="home">
    <div class="item" v-for ="item of musics" :key="item.id" @click="handleDetail(item.id)">
      <img :src="item.coverImgUrl" alt="">
      <p>{{item.name}}</p>
    </div>
  </div>
</template>

<script>
import { reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
export default {
  name: 'Home',
  setup(){
    const state = reactive({
      musics:[],
      handleDetail(id){
        // console.log(id);
        this.$router.push(`/detail?id=${id}`)
      }
    })
    onMounted(()=>{
      axios.get("http://122.112.161.135:3000/top/playlist").then(res=>{
        // console.log(res.data);
        state.musics = res.data.playlists
      })

    })
    const refState = toRefs(state);
    return{
      ...refState
    }
  }
}
</script>
<style scoped>
.home{
  display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}
  .item{
    
    width: 280px;
  }
  .item img{
    width: 250px;
    height: 250px;
  }
</style>